/*      */ package com.zimbra.cs.util.tnef;
/*      */ 
/*      */ import com.zimbra.common.util.Log;
/*      */ import com.zimbra.common.util.ZimbraLog;
/*      */ import com.zimbra.cs.util.tnef.mapi.AppointmentStateFlags;
/*      */ import com.zimbra.cs.util.tnef.mapi.BusyStatus;
/*      */ import com.zimbra.cs.util.tnef.mapi.GlobalObjectId;
/*      */ import com.zimbra.cs.util.tnef.mapi.MapiPropertyId;
/*      */ import com.zimbra.cs.util.tnef.mapi.MeetingTypeFlag;
/*      */ import com.zimbra.cs.util.tnef.mapi.RecurrenceDefinition;
/*      */ import com.zimbra.cs.util.tnef.mapi.TZRule;
/*      */ import com.zimbra.cs.util.tnef.mapi.TaskMode;
/*      */ import com.zimbra.cs.util.tnef.mapi.TaskStatus;
/*      */ import com.zimbra.cs.util.tnef.mapi.TimeZoneDefinition;
/*      */ import java.io.IOException;
/*      */ import java.text.ParseException;
/*      */ import java.util.ArrayList;
/*      */ import java.util.EnumSet;
/*      */ import java.util.List;
/*      */ import net.fortuna.ical4j.model.DateTime;
/*      */ import net.fortuna.ical4j.model.property.Clazz;
/*      */ import net.freeutils.tnef.Attachment;
/*      */ import net.freeutils.tnef.Attr;
/*      */ import net.freeutils.tnef.CompressedRTFInputStream;
/*      */ import net.freeutils.tnef.MAPIProps;
/*      */ import net.freeutils.tnef.MAPIValue;
/*      */ import net.freeutils.tnef.Message;
/*      */ import net.freeutils.tnef.RawInputStream;
/*      */ import net.freeutils.tnef.TNEFInputStream;
/*      */ import net.freeutils.tnef.TNEFUtils;
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ public class SchedulingViewOfTnef
/*      */   extends Message
/*      */ {
/*   62 */   static Log sLog = ZimbraLog.tnef;
/*      */   
/*      */   private String messageClass;
/*      */   private GlobalObjectId globalObjectId;
/*      */   private GlobalObjectId cleanGlobalObjectId;
/*      */   private boolean tzinfoInitialized;
/*      */   private TimeZoneDefinition startTimeTZinfo;
/*      */   private TimeZoneDefinition endTimeTZinfo;
/*      */   private TimeZoneDefinition recurrenceTZinfo;
/*      */   private EnumSet<AppointmentStateFlags> appointmentStateFlagsMask;
/*      */   private TaskMode taskMode;
/*      */   private TaskStatus taskStatus;
/*      */   private Integer percentComplete;
/*      */   private DateTime dateTaskCompleted;
/*      */   private ICALENDAR_TYPE icalType;
/*      */   
/*      */   public SchedulingViewOfTnef()
/*      */   {
/*   80 */     List<Attr> attribs = new ArrayList();
/*   81 */     List<Attachment> attaches = new ArrayList();
/*   82 */     setAttributes(attribs);
/*   83 */     setAttachments(attaches);
/*   84 */     this.messageClass = null;
/*   85 */     this.globalObjectId = null;
/*   86 */     this.cleanGlobalObjectId = null;
/*   87 */     this.appointmentStateFlagsMask = null;
/*   88 */     this.tzinfoInitialized = false;
/*   89 */     this.startTimeTZinfo = null;
/*   90 */     this.endTimeTZinfo = null;
/*   91 */     this.recurrenceTZinfo = null;
/*   92 */     this.taskMode = null;
/*   93 */     this.taskStatus = null;
/*   94 */     this.percentComplete = null;
/*   95 */     this.icalType = null;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public SchedulingViewOfTnef(TNEFInputStream in)
/*      */     throws IOException
/*      */   {
/*  106 */     this();
/*  107 */     read(in);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   protected void read(TNEFInputStream in)
/*      */     throws IOException
/*      */   {
/*  119 */     Attachment attachmnt = null;
/*  120 */     Attr attr; while ((attr = in.readAttr()) != null) {
/*  121 */       switch (attr.getLevel()) {
/*      */       case 2: 
/*  123 */         switch (attr.getID()) {
/*      */         case 36866: 
/*  125 */           if (attachmnt != null) {
/*  126 */             super.addAttachment(attachmnt);
/*      */           }
/*  128 */           attachmnt = new Attachment();
/*  129 */           attachmnt.addAttribute(attr);
/*  130 */           break;
/*      */         case 36869: 
/*  132 */           MAPIProps mps = new MAPIProps((RawInputStream)attr.getValue());
/*  133 */           attachmnt.setMAPIProps(mps);
/*  134 */           break;
/*      */         case 32783: 
/*  136 */           RawInputStream ris = (RawInputStream)attr.getValue();
/*  137 */           attachmnt.setRawData(ris);
/*  138 */           break;
/*      */         case 36865: 
/*  140 */           RawInputStream data = (RawInputStream)attr.getValue();
/*  141 */           String filename = TNEFUtils.removeTerminatingNulls(new String(data.toByteArray(), super.getOEMCodePage()));
/*      */           
/*      */ 
/*  144 */           attachmnt.setFilename(filename);
/*  145 */           break;
/*      */         default: 
/*  147 */           attachmnt.addAttribute(attr);
/*      */         }
/*      */         
/*  150 */         break;
/*      */       case 1: 
/*  152 */         super.addAttribute(attr);
/*  153 */         break;
/*      */       default: 
/*  155 */         throw new IOException("Invalid attribute level: " + attr.getLevel());
/*      */       }
/*      */       
/*      */     }
/*  159 */     if (attachmnt != null) {
/*  160 */       super.addAttachment(attachmnt);
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public String getMessageClass()
/*      */     throws IOException
/*      */   {
/*  169 */     if (this.messageClass != null) {
/*  170 */       return this.messageClass;
/*      */     }
/*  172 */     Attr attMsgClass = getAttr(32776);
/*  173 */     if (attMsgClass == null) {
/*  174 */       return null;
/*      */     }
/*  176 */     this.messageClass = attMsgClass.getValue().toString();
/*  177 */     return this.messageClass;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public String getIcalUID()
/*      */     throws IOException
/*      */   {
/*  190 */     getGlobalObjectId();
/*  191 */     if (this.globalObjectId != null) {
/*  192 */       return this.globalObjectId.getIcalUid();
/*      */     }
/*  194 */     getCleanGlobalObjectId();
/*  195 */     if (this.cleanGlobalObjectId != null) {
/*  196 */       return this.cleanGlobalObjectId.getIcalUid();
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  205 */     String currUid = getUrnSchemasCalendarUid();
/*  206 */     if (currUid != null) {
/*  207 */       return currUid;
/*      */     }
/*  209 */     return getUidFromPidLidTaskGlobalId();
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public Integer getSequenceNumber()
/*      */     throws IOException
/*      */   {
/*  217 */     if (getIcalType() == ICALENDAR_TYPE.VTODO) {
/*  218 */       Integer retVal = MapiPropertyId.PidLidTaskVersion.getIntegerValue(this);
/*  219 */       if (retVal != null) {
/*  220 */         return retVal;
/*      */       }
/*      */     }
/*      */     
/*  224 */     return MapiPropertyId.PidLidAppointmentSequence.getIntegerValue(this, 0);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public Integer getMapiImportance()
/*      */     throws IOException
/*      */   {
/*  232 */     return MapiPropertyId.PidTagImportance.getIntegerValue(this);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public Integer getOwnerAppointmentId()
/*      */     throws IOException
/*      */   {
/*  241 */     return MapiPropertyId.PidTagOwnerAppointmentId.getIntegerValue(this);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public Clazz getIcalClass()
/*      */     throws IOException
/*      */   {
/*  256 */     Integer mapiSensitivity = getMapiSensitivity();
/*  257 */     if (mapiSensitivity == null) {
/*  258 */       return Clazz.PUBLIC;
/*      */     }
/*  260 */     if (mapiSensitivity.intValue() == 0)
/*  261 */       return Clazz.PUBLIC;
/*  262 */     if (mapiSensitivity.intValue() == 1)
/*      */     {
/*  264 */       return Clazz.PRIVATE; }
/*  265 */     if (mapiSensitivity.intValue() == 2)
/*  266 */       return Clazz.PRIVATE;
/*  267 */     if (mapiSensitivity.intValue() == 3) {
/*  268 */       return Clazz.CONFIDENTIAL;
/*      */     }
/*  270 */     return Clazz.PUBLIC;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public Integer getMapiSensitivity()
/*      */     throws IOException
/*      */   {
/*  285 */     return MapiPropertyId.PidTagSensitivity.getIntegerValue(this);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public BusyStatus getBusyStatus()
/*      */     throws IOException
/*      */   {
/*  300 */     Integer intVal = MapiPropertyId.PidLidBusyStatus.getIntegerValue(this);
/*  301 */     if (intVal == null) {
/*  302 */       return null;
/*      */     }
/*  304 */     for (BusyStatus curr : BusyStatus.values()) {
/*  305 */       if (curr.mapiPropValue() == intVal.intValue()) {
/*  306 */         return curr;
/*      */       }
/*      */     }
/*  309 */     return null;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public BusyStatus getIntendedBusyStatus()
/*      */     throws IOException
/*      */   {
/*  320 */     Integer intVal = MapiPropertyId.PidLidIntendedBusyStatus.getIntegerValue(this);
/*  321 */     if (intVal == null) {
/*  322 */       return null;
/*      */     }
/*  324 */     for (BusyStatus curr : BusyStatus.values()) {
/*  325 */       if (curr.mapiPropValue() == intVal.intValue()) {
/*  326 */         return curr;
/*      */       }
/*      */     }
/*  329 */     return null;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public EnumSet<AppointmentStateFlags> getAppointmentStateFlags()
/*      */     throws IOException
/*      */   {
/*  342 */     if (this.appointmentStateFlagsMask != null) {
/*  343 */       return this.appointmentStateFlagsMask;
/*      */     }
/*  345 */     this.appointmentStateFlagsMask = EnumSet.noneOf(AppointmentStateFlags.class);
/*  346 */     Integer apptFlags = MapiPropertyId.PidLidAppointmentStateFlags.getIntegerValue(this);
/*  347 */     if (apptFlags == null) {
/*  348 */       return null;
/*      */     }
/*  350 */     if ((apptFlags.intValue() & 0x1) == 1) {
/*  351 */       this.appointmentStateFlagsMask.add(AppointmentStateFlags.ASF_MEETING);
/*      */     }
/*  353 */     if ((apptFlags.intValue() & 0x2) == 2) {
/*  354 */       this.appointmentStateFlagsMask.add(AppointmentStateFlags.ASF_RECEIVED);
/*      */     }
/*  356 */     if ((apptFlags.intValue() & 0x4) == 4) {
/*  357 */       this.appointmentStateFlagsMask.add(AppointmentStateFlags.ASF_CANCELED);
/*      */     }
/*  359 */     return this.appointmentStateFlagsMask;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public boolean getResponseRequested()
/*      */     throws IOException
/*      */   {
/*  367 */     Boolean responseRequested = MapiPropertyId.PidTagResponseRequested.getBooleanValue(this);
/*      */     
/*  369 */     if (responseRequested != null) {
/*  370 */       return responseRequested.booleanValue();
/*      */     }
/*  372 */     Boolean replyRequested = MapiPropertyId.PidTagReplyRequested.getBooleanValue(this);
/*      */     
/*  374 */     if (replyRequested != null) {
/*  375 */       return replyRequested.booleanValue();
/*      */     }
/*  377 */     return false;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public Boolean isAllDayEvent()
/*      */     throws IOException
/*      */   {
/*  386 */     return MapiPropertyId.PidLidAppointmentSubType.getBooleanValue(this, false);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public Boolean isCounterProposal()
/*      */     throws IOException
/*      */   {
/*  396 */     return MapiPropertyId.PidLidAppointmentCounterProposal.getBooleanValue(this, false);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public Boolean isDisallowCounter()
/*      */     throws IOException
/*      */   {
/*  406 */     return MapiPropertyId.PidLidAppointmentNotAllowPropose.getBooleanValue(this);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public String getLocation()
/*      */     throws IOException
/*      */   {
/*  414 */     return MapiPropertyId.PidLidLocation.getStringValue(this);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public List<String> getCategories()
/*      */     throws IOException
/*      */   {
/*  422 */     MAPIValue[] values = MapiPropertyId.PidNameKeywords.getValues(this);
/*  423 */     if (values == null) {
/*  424 */       return null;
/*      */     }
/*  426 */     ArrayList<String> categories = new ArrayList();
/*  427 */     for (MAPIValue val : values) {
/*  428 */       categories.add(val.toString());
/*      */     }
/*  430 */     return categories;
/*      */   }
/*      */   
/*      */   public String getMileage() throws IOException {
/*  434 */     return MapiPropertyId.PidLidMileage.getStringValue(this);
/*      */   }
/*      */   
/*      */   public String getBillingInfo() throws IOException {
/*  438 */     return MapiPropertyId.PidLidBilling.getStringValue(this);
/*      */   }
/*      */   
/*      */   public String getCompanies() throws IOException {
/*  442 */     return MapiPropertyId.PidLidCompanies.getStringValue(this);
/*      */   }
/*      */   
/*      */   public Integer getEstimatedEffort() throws IOException {
/*  446 */     Integer myVal = MapiPropertyId.PidLidTaskEstimatedEffort.getIntegerValue(this);
/*  447 */     if ((myVal == null) || (myVal.intValue() == 0)) {
/*  448 */       return null;
/*      */     }
/*  450 */     return myVal;
/*      */   }
/*      */   
/*      */   public Integer getActualEffort() throws IOException {
/*  454 */     Integer myVal = MapiPropertyId.PidLidTaskActualEffort.getIntegerValue(this);
/*  455 */     if ((myVal == null) || (myVal.intValue() == 0)) {
/*  456 */       return null;
/*      */     }
/*  458 */     return myVal;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public DateTime getOwnerCriticalChange()
/*      */     throws IOException
/*      */   {
/*  468 */     return MapiPropertyId.PidLidOwnerCriticalChange.getDateTimeAsUTC(this);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public DateTime getAppointmentReplyTime()
/*      */     throws IOException
/*      */   {
/*  478 */     return MapiPropertyId.PidLidAppointmentReplyTime.getDateTimeAsUTC(this);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public Integer getReminderDelta()
/*      */     throws IOException
/*      */   {
/*  491 */     Integer reminderDelta = MapiPropertyId.PidLidReminderDelta.getIntegerValue(this);
/*      */     
/*  493 */     if ((reminderDelta != null) && (reminderDelta.intValue() == 1525252321)) {
/*  494 */       reminderDelta = Integer.valueOf(15);
/*      */     }
/*  496 */     return reminderDelta;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public boolean getReminderSet()
/*      */     throws IOException
/*      */   {
/*  507 */     return MapiPropertyId.PidLidReminderSet.getBooleanValue(this, false).booleanValue();
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public DateTime getStartTime()
/*      */     throws IOException
/*      */   {
/*  516 */     DateTime timeVal = null;
/*  517 */     if (getIcalType() == ICALENDAR_TYPE.VTODO)
/*      */     {
/*      */ 
/*      */ 
/*  521 */       Long taskStartDateNum = MapiPropertyId.PidLidTaskStartDate.get100nsPeriodsSince1601(this);
/*      */       
/*  523 */       if (taskStartDateNum == null) {
/*  524 */         return null;
/*      */       }
/*  526 */       if (taskStartDateNum.longValue() == 1525252320L) {
/*  527 */         sLog.debug("PidLidTaskStartDate as num 0x%s [means NO start date]", new Object[] { Long.toHexString(taskStartDateNum.longValue()) });
/*      */         
/*  529 */         return null;
/*      */       }
/*  531 */       timeVal = MapiPropertyId.PidLidTaskStartDate.getDateTimeAsUTC(this);
/*      */     }
/*      */     else
/*      */     {
/*  535 */       timeVal = MapiPropertyId.PidLidAppointmentStartWhole.getDateTimeAsUTC(this);
/*      */     }
/*      */     
/*  538 */     if (timeVal == null) {
/*  539 */       timeVal = MapiPropertyId.PidTagStartDate.getDateTimeAsUTC(this);
/*      */     }
/*  541 */     return timeVal;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public DateTime getEndTime()
/*      */     throws IOException
/*      */   {
/*  550 */     DateTime timeVal = MapiPropertyId.PidLidAppointmentEndWhole.getDateTimeAsUTC(this);
/*      */     
/*  552 */     if (timeVal == null) {
/*  553 */       timeVal = MapiPropertyId.PidTagEndDate.getDateTimeAsUTC(this);
/*      */     }
/*  555 */     return timeVal;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public DateTime getDueDate()
/*      */     throws IOException
/*      */   {
/*  563 */     DateTime timeVal = null;
/*  564 */     if (getIcalType() != ICALENDAR_TYPE.VTODO) {
/*  565 */       return null;
/*      */     }
/*  567 */     timeVal = MapiPropertyId.PidLidTaskDueDate.getDateTimeAsUTC(this);
/*      */     
/*  569 */     return timeVal;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public DateTime getRecurrenceIdTime()
/*      */     throws IOException
/*      */   {
/*  586 */     DateTime recurrenceIdTime = MapiPropertyId.PidLidExceptionReplaceTime.getDateTimeAsUTC(this);
/*      */     
/*  588 */     if (recurrenceIdTime != null) {
/*  589 */       sLog.debug("RECURRENCE-ID taken from PidLidExceptionReplaceTime");
/*      */     } else {
/*  591 */       getGlobalObjectId();
/*  592 */       if (this.globalObjectId == null) {
/*  593 */         return null;
/*      */       }
/*  595 */       int origYear = this.globalObjectId.getOrigInstanceYear();
/*  596 */       if (origYear == 0) {
/*  597 */         return null;
/*      */       }
/*  599 */       int origMonth = this.globalObjectId.getOrigInstanceMonth();
/*  600 */       int origDay = this.globalObjectId.getOrigInstanceDay();
/*      */       
/*  602 */       Integer recurTime = MapiPropertyId.PidLidStartRecurrenceTime.getIntegerValue(this);
/*      */       
/*  604 */       int secs = 0;
/*  605 */       int mins = 0;
/*  606 */       int hrs = 0;
/*  607 */       if (recurTime != null)
/*      */       {
/*  609 */         secs = recurTime.intValue() & 0x3F;
/*  610 */         mins = (recurTime.intValue() & 0xFC0) >> 6;
/*  611 */         hrs = (recurTime.intValue() & 0xF000) >> 12;
/*  612 */         sLog.debug("RECURRENCE-ID taken from GlobalObjectId/PidLidStartRecurrenceTime");
/*      */       } else {
/*  614 */         sLog.debug("RECURRENCE-ID taken from JUST GlobalObjectId");
/*      */       }
/*      */       try
/*      */       {
/*  618 */         if (this.recurrenceTZinfo == null) {
/*  619 */           String dateString = String.format("%04d%02d%02dT%02d%02d%02dZ", new Object[] { Integer.valueOf(origYear), Integer.valueOf(origMonth), Integer.valueOf(origDay), Integer.valueOf(hrs), Integer.valueOf(mins), Integer.valueOf(secs) });
/*      */           
/*  621 */           recurrenceIdTime = new DateTime(dateString);
/*      */         } else {
/*  623 */           String dateString = String.format("%04d%02d%02dT%02d%02d%02d", new Object[] { Integer.valueOf(origYear), Integer.valueOf(origMonth), Integer.valueOf(origDay), Integer.valueOf(hrs), Integer.valueOf(mins), Integer.valueOf(secs) });
/*      */           
/*  625 */           recurrenceIdTime = new DateTime(dateString, this.recurrenceTZinfo.getTimeZone());
/*      */         }
/*      */       } catch (ParseException e) {
/*  628 */         sLog.debug("Problem constructing recurrence-id time", e);
/*      */       }
/*      */     }
/*  631 */     return recurrenceIdTime;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public DateTime getProposedStartTime()
/*      */     throws IOException
/*      */   {
/*  640 */     return MapiPropertyId.PidLidAppointmentProposedStartWhole.getDateTimeAsUTC(this);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public DateTime getProposedEndTime()
/*      */     throws IOException
/*      */   {
/*  650 */     return MapiPropertyId.PidLidAppointmentProposedEndWhole.getDateTimeAsUTC(this);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public DateTime getAttendeeCriticalChange()
/*      */     throws IOException
/*      */   {
/*  659 */     return MapiPropertyId.PidLidAttendeeCriticalChange.getDateTimeAsUTC(this);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public TimeZoneDefinition getStartDateTimezoneInfo()
/*      */     throws IOException
/*      */   {
/*  667 */     initTZinfo();
/*  668 */     return this.startTimeTZinfo;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public TimeZoneDefinition getEndDateTimezoneInfo()
/*      */     throws IOException
/*      */   {
/*  676 */     initTZinfo();
/*  677 */     return this.endTimeTZinfo;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public TimeZoneDefinition getRecurrenceTimezoneInfo()
/*      */     throws IOException
/*      */   {
/*  685 */     initTZinfo();
/*  686 */     return this.recurrenceTZinfo;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public String getTimeZoneDescription()
/*      */     throws IOException
/*      */   {
/*  697 */     return MapiPropertyId.PidLidTimeZoneDescription.getStringValue(this);
/*      */   }
/*      */   
/*      */   public RecurrenceDefinition getRecurrenceDefinition(TimeZoneDefinition tzDef) throws IOException, TNEFtoIcalendarServiceException {
/*      */     RawInputStream tzRis;
/*      */     RawInputStream tzRis;
/*  703 */     if (getIcalType() == ICALENDAR_TYPE.VTODO) {
/*  704 */       tzRis = MapiPropertyId.PidLidTaskRecurrence.getRawInputStreamValue(this);
/*      */     } else {
/*  706 */       tzRis = MapiPropertyId.PidLidAppointmentRecur.getRawInputStreamValue(this);
/*      */     }
/*  708 */     if (tzRis == null) {
/*  709 */       return null;
/*      */     }
/*  711 */     String oemCodePage = super.getOEMCodePage();
/*  712 */     RecurrenceDefinition recurDef = new RecurrenceDefinition(tzRis, tzDef, oemCodePage);
/*  713 */     return recurDef;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public String getRTF()
/*      */     throws IOException
/*      */   {
/*  724 */     RawInputStream ris = MapiPropertyId.PidTagRtfCompressed.getRawInputStreamValue(this);
/*  725 */     if (ris == null) {
/*  726 */       sLog.debug("No PR_RTF_COMPRESSED property found");
/*  727 */       return null;
/*      */     }
/*      */     
/*  730 */     String rtfTxt = new String(CompressedRTFInputStream.decompressRTF(ris.toByteArray()));
/*      */     
/*      */ 
/*  733 */     if (sLog.isDebugEnabled()) {
/*  734 */       sLog.debug("RTF from PR_RTF_COMPRESSED\n%s\n", new Object[] { rtfTxt });
/*      */     }
/*  736 */     return rtfTxt;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public Attr getAttr(int attrib)
/*      */     throws IOException
/*      */   {
/*  747 */     List<?> attribs = super.getAttributes();
/*  748 */     for (Object thisObj : attribs) {
/*  749 */       if ((thisObj instanceof Attr))
/*      */       {
/*      */ 
/*  752 */         Attr thisAtt = (Attr)thisObj;
/*  753 */         if (thisAtt.getID() == attrib)
/*  754 */           return thisAtt;
/*      */       }
/*      */     }
/*  757 */     return null;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private GlobalObjectId getGlobalObjectId()
/*      */   {
/*  766 */     if (this.globalObjectId != null) {
/*  767 */       return this.globalObjectId;
/*      */     }
/*  769 */     this.globalObjectId = getGlobalObjectIdType(MapiPropertyId.PidLidGlobalObjectId);
/*  770 */     return this.globalObjectId;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private GlobalObjectId getCleanGlobalObjectId()
/*      */   {
/*  785 */     if (this.cleanGlobalObjectId != null) {
/*  786 */       return this.cleanGlobalObjectId;
/*      */     }
/*  788 */     this.cleanGlobalObjectId = getGlobalObjectIdType(MapiPropertyId.PidLidCleanGlobalObjectId);
/*      */     
/*  790 */     return this.cleanGlobalObjectId;
/*      */   }
/*      */   
/*      */   private GlobalObjectId getGlobalObjectIdType(MapiPropertyId mpi) {
/*  794 */     GlobalObjectId gid = null;
/*      */     try
/*      */     {
/*  797 */       RawInputStream ris = mpi.getRawInputStreamValue(this);
/*  798 */       if (ris != null) {
/*  799 */         gid = new GlobalObjectId(ris);
/*      */       }
/*      */     } catch (IOException e) {
/*  802 */       sLog.debug("Problem getting value of MAPI property " + mpi.toString() + " from TNEF", e);
/*      */     }
/*  804 */     return gid;
/*      */   }
/*      */   
/*      */   public EnumSet<MeetingTypeFlag> getMeetingTypeFlags() throws IOException {
/*  808 */     EnumSet<MeetingTypeFlag> meetingTypeFlags = EnumSet.noneOf(MeetingTypeFlag.class);
/*  809 */     Integer mtgType = MapiPropertyId.PidLidMeetingType.getIntegerValue(this);
/*  810 */     if (mtgType != null) {
/*  811 */       for (MeetingTypeFlag curr : MeetingTypeFlag.values()) {
/*  812 */         int currFlagBit = curr.mapiFlagBit();
/*  813 */         if ((mtgType.intValue() & currFlagBit) == currFlagBit) {
/*  814 */           meetingTypeFlags.add(curr);
/*      */         }
/*      */       }
/*      */     }
/*  818 */     return meetingTypeFlags;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   private String getUrnSchemasCalendarUid()
/*      */     throws IOException
/*      */   {
/*  826 */     return MapiPropertyId.PidNameCalendarUid.getStringValue(this);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private String getUidFromPidLidTaskGlobalId()
/*      */     throws IOException
/*      */   {
/*  842 */     byte[] theVal = MapiPropertyId.PidLidTaskGlobalId.getByteArrayValue(this);
/*  843 */     if (theVal == null) {
/*  844 */       return null;
/*      */     }
/*  846 */     return IcalUtil.toHexString(theVal, 0, theVal.length);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void setIcalType(ICALENDAR_TYPE icalType)
/*      */   {
/*  853 */     this.icalType = icalType;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public ICALENDAR_TYPE getIcalType()
/*      */     throws IOException
/*      */   {
/*  861 */     if (this.icalType == null) {
/*  862 */       String msgClass = getMessageClass();
/*  863 */       if (msgClass.startsWith("IPM.Task")) {
/*  864 */         this.icalType = ICALENDAR_TYPE.VTODO;
/*      */       } else {
/*  866 */         this.icalType = ICALENDAR_TYPE.VEVENT;
/*      */       }
/*      */     }
/*  869 */     return this.icalType;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public TaskMode getTaskMode()
/*      */     throws IOException
/*      */   {
/*  877 */     initTaskStatusInfo();
/*  878 */     return this.taskMode;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public TaskStatus getTaskStatus()
/*      */     throws IOException
/*      */   {
/*  886 */     initTaskStatusInfo();
/*  887 */     return this.taskStatus;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public int getPercentComplete()
/*      */     throws IOException
/*      */   {
/*  895 */     initTaskStatusInfo();
/*  896 */     if (this.percentComplete == null) {
/*  897 */       return 0;
/*      */     }
/*  899 */     return this.percentComplete.intValue();
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public DateTime getDateTaskCompleted()
/*      */     throws IOException
/*      */   {
/*  908 */     initTaskStatusInfo();
/*  909 */     return this.dateTaskCompleted;
/*      */   }
/*      */   
/*      */   private void initTaskStatusInfo() throws IOException {
/*  913 */     if (getIcalType() != ICALENDAR_TYPE.VTODO) {
/*  914 */       return;
/*      */     }
/*  916 */     if (this.percentComplete != null) {
/*  917 */       return;
/*      */     }
/*  919 */     this.dateTaskCompleted = MapiPropertyId.PidLidTaskDateCompleted.getDateTimeAsUTC(this);
/*      */     
/*      */ 
/*  922 */     this.taskMode = TaskMode.TASK_REQUEST;
/*  923 */     Integer intVal = MapiPropertyId.PidLidTaskMode.getIntegerValue(this);
/*  924 */     if (intVal != null) {
/*  925 */       for (TaskMode curr : TaskMode.values()) {
/*  926 */         if (curr.mapiPropValue() == intVal.intValue()) {
/*  927 */           this.taskMode = curr;
/*  928 */           break;
/*      */         }
/*      */       }
/*      */     }
/*  932 */     if (this.dateTaskCompleted != null) {
/*  933 */       this.taskStatus = TaskStatus.COMPLETE;
/*  934 */       this.percentComplete = Integer.valueOf(100);
/*      */     } else {
/*  936 */       this.taskStatus = TaskStatus.NOT_STARTED;
/*  937 */       intVal = MapiPropertyId.PidLidTaskStatus.getIntegerValue(this);
/*  938 */       if (intVal != null) {
/*  939 */         for (TaskStatus curr : TaskStatus.values()) {
/*  940 */           if (curr.mapiPropValue() == intVal.intValue()) {
/*  941 */             this.taskStatus = curr;
/*  942 */             break;
/*      */           }
/*      */         }
/*      */       }
/*      */       
/*  947 */       Double fractionComplete = MapiPropertyId.PidLidPercentComplete.getDoubleValue(this);
/*  948 */       if ((fractionComplete == null) || (fractionComplete.doubleValue() < 0.0D) || (fractionComplete.doubleValue() > 1.0D)) {
/*  949 */         this.percentComplete = Integer.valueOf(0);
/*      */       } else {
/*  951 */         fractionComplete = Double.valueOf(fractionComplete.doubleValue() * 100.0D);
/*  952 */         this.percentComplete = Integer.valueOf((int)Math.round(fractionComplete.doubleValue()));
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private void initTZinfo()
/*      */   {
/*  975 */     if (this.tzinfoInitialized) {
/*  976 */       return;
/*      */     }
/*      */     
/*      */ 
/*      */     try
/*      */     {
/*  982 */       MapiPropertyId mpi = MapiPropertyId.PidLidAppointmentTimeZoneDefinitionStartDisplay;
/*  983 */       RawInputStream tzRis = mpi.getRawInputStreamValue(this);
/*  984 */       if (tzRis != null) {
/*  985 */         this.startTimeTZinfo = new TimeZoneDefinition(mpi, tzRis);
/*      */       }
/*  987 */       mpi = MapiPropertyId.PidLidAppointmentTimeZoneDefinitionEndDisplay;
/*  988 */       tzRis = mpi.getRawInputStreamValue(this);
/*  989 */       if (tzRis != null) {
/*  990 */         this.endTimeTZinfo = new TimeZoneDefinition(mpi, tzRis);
/*      */       }
/*  992 */       mpi = MapiPropertyId.PidLidAppointmentTimeZoneDefinitionRecur;
/*  993 */       tzRis = mpi.getRawInputStreamValue(this);
/*  994 */       if (tzRis != null) {
/*  995 */         this.recurrenceTZinfo = new TimeZoneDefinition(mpi, tzRis);
/*      */       }
/*  997 */       String tzDesc = getTimeZoneDescription();
/*  998 */       if (null != tzDesc) {
/*  999 */         TimeZoneDefinition tzStructInfo = getTimeZoneStructInfo(tzDesc);
/* 1000 */         if (tzStructInfo != null)
/*      */         {
/*      */ 
/* 1003 */           TZRule tzsRule = tzStructInfo.getEffectiveRule();
/* 1004 */           if (this.recurrenceTZinfo == null) {
/* 1005 */             if ((this.startTimeTZinfo != null) && (tzsRule.equivalentRule(this.startTimeTZinfo.getEffectiveRule())))
/*      */             {
/*      */ 
/* 1008 */               this.recurrenceTZinfo = this.startTimeTZinfo;
/* 1009 */               sLog.debug("Using %s for TZ info", new Object[] { "PidLidAppointmentTimeZoneDefinitionStart" });
/*      */             }
/* 1011 */             else if ((this.endTimeTZinfo != null) && (tzsRule.equivalentRule(this.endTimeTZinfo.getEffectiveRule())))
/*      */             {
/*      */ 
/* 1014 */               this.recurrenceTZinfo = this.endTimeTZinfo;
/* 1015 */               sLog.debug("Using %s for TZ info", new Object[] { "PidLidAppointmentTimeZoneDefinitionEnd" });
/*      */             }
/*      */             else {
/* 1018 */               this.recurrenceTZinfo = tzStructInfo;
/* 1019 */               sLog.debug("Using %s for TZ info", new Object[] { "PidLidTimeZoneStruct" });
/*      */             }
/*      */           }
/* 1022 */           else if (!tzsRule.equivalentRule(this.recurrenceTZinfo.getEffectiveRule()))
/*      */           {
/* 1024 */             this.recurrenceTZinfo = tzStructInfo;
/* 1025 */             sLog.debug("Using %s for TZ info", new Object[] { "PidLidAppointmentTimeZoneDefinitionRecur" });
/*      */           }
/*      */         }
/*      */       }
/*      */     }
/*      */     catch (IOException e) {
/* 1031 */       sLog.debug("Problem encountered initialising timezone information", e);
/*      */     }
/*      */     
/* 1034 */     if (this.recurrenceTZinfo != null)
/*      */     {
/* 1036 */       if (this.endTimeTZinfo == null) {
/* 1037 */         this.endTimeTZinfo = this.recurrenceTZinfo;
/* 1038 */       } else if (this.recurrenceTZinfo.getEffectiveRule().equivalentRule(this.endTimeTZinfo.getEffectiveRule()))
/*      */       {
/* 1040 */         this.endTimeTZinfo = this.recurrenceTZinfo;
/* 1041 */       } else if (this.startTimeTZinfo != null)
/*      */       {
/*      */ 
/* 1044 */         if (this.startTimeTZinfo.getEffectiveRule().equivalentRule(this.endTimeTZinfo.getEffectiveRule()))
/*      */         {
/* 1046 */           this.endTimeTZinfo = this.recurrenceTZinfo;
/*      */         }
/*      */       }
/* 1049 */       this.startTimeTZinfo = this.recurrenceTZinfo;
/*      */     }
/* 1051 */     if (this.endTimeTZinfo == null) {
/* 1052 */       this.endTimeTZinfo = this.startTimeTZinfo;
/* 1053 */     } else if (this.startTimeTZinfo == null) {
/* 1054 */       this.startTimeTZinfo = this.endTimeTZinfo;
/* 1055 */     } else if (this.startTimeTZinfo.getEffectiveRule().equivalentRule(this.endTimeTZinfo.getEffectiveRule()))
/*      */     {
/* 1057 */       this.endTimeTZinfo = this.startTimeTZinfo;
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private TimeZoneDefinition getTimeZoneStructInfo(String tzName)
/*      */     throws IOException
/*      */   {
/* 1069 */     RawInputStream tzRis = MapiPropertyId.PidLidTimeZoneStruct.getRawInputStreamValue(this);
/*      */     
/* 1071 */     if (tzRis == null) {
/* 1072 */       return null;
/*      */     }
/* 1074 */     TimeZoneDefinition tzDef = new TimeZoneDefinition(tzRis, tzName);
/* 1075 */     if ((tzDef == null) && 
/* 1076 */       (sLog.isDebugEnabled())) {
/* 1077 */       sLog.debug("Failed to load TimeZoneDefinition from PidLidTimeZoneStruct and " + tzName);
/*      */     }
/*      */     
/* 1080 */     return tzDef;
/*      */   }
/*      */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/util/tnef/SchedulingViewOfTnef.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */